﻿using System;
using System.Runtime.InteropServices;
using UnityEngine;

namespace RenderHeads.Media.AVProVideo
{
	// Token: 0x02000043 RID: 67
	public sealed class WindowsMediaPlayer : BaseMediaPlayer
	{
		// Token: 0x06000206 RID: 518 RVA: 0x0000B714 File Offset: 0x00009914
		public WindowsMediaPlayer(Windows.VideoApi videoApi, bool useHardwareDecoding, bool useTextureMips, string audioDeviceOutputName, bool useUnityAudio, bool forceResample, int channels)
		{
			this.SetOptions(videoApi, useHardwareDecoding, useTextureMips, audioDeviceOutputName, useUnityAudio, forceResample, channels);
		}

		// Token: 0x06000207 RID: 519 RVA: 0x0000B7B0 File Offset: 0x000099B0
		public static void InitialisePlatform()
		{
			if (!WindowsMediaPlayer._isInitialised)
			{
				if (!WindowsMediaPlayer.Native.Init(QualitySettings.activeColorSpace == ColorSpace.Linear, true))
				{
					GlobalData.Debug_LogError("[AVProVideo] Failing to initialise platform");
				}
				else
				{
					WindowsMediaPlayer._version = WindowsMediaPlayer.GetPluginVersion();
					WindowsMediaPlayer._nativeFunction_UpdateAllTextures = WindowsMediaPlayer.Native.GetRenderEventFunc_UpdateAllTextures();
					WindowsMediaPlayer._nativeFunction_FreeTextures = WindowsMediaPlayer.Native.GetRenderEventFunc_FreeTextures();
				}
			}
		}

		// Token: 0x06000208 RID: 520 RVA: 0x0000B808 File Offset: 0x00009A08
		public static void DeinitPlatform()
		{
			WindowsMediaPlayer.Native.Deinit();
		}

		// Token: 0x06000209 RID: 521 RVA: 0x0000B810 File Offset: 0x00009A10
		public override int GetNumAudioChannels()
		{
			return WindowsMediaPlayer.Native.GetAudioChannelCount(this._instance);
		}

		// Token: 0x0600020A RID: 522 RVA: 0x0000B820 File Offset: 0x00009A20
		private static int CalculateClosestViableChannelNumber(int channels)
		{
			int max;
			switch (AudioSettings.speakerMode)
			{
			case AudioSpeakerMode.Mono:
				max = 1;
				break;
			case AudioSpeakerMode.Stereo:
				max = 2;
				break;
			case AudioSpeakerMode.Quad:
				max = 4;
				break;
			case AudioSpeakerMode.Surround:
				max = 5;
				break;
			case AudioSpeakerMode.Mode5point1:
				max = 6;
				break;
			case AudioSpeakerMode.Mode7point1:
				max = 8;
				break;
			default:
				max = 2;
				break;
			}
			channels = Mathf.Clamp(channels, 1, max);
			int[] array = new int[]
			{
				8,
				6,
				5,
				4,
				2,
				1
			};
			for (int i = 0; i < array.Length; i++)
			{
				if (channels >= array[i])
				{
					return array[i];
				}
			}
			return 2;
		}

		// Token: 0x0600020B RID: 523 RVA: 0x0000B8CC File Offset: 0x00009ACC
		public void SetOptions(Windows.VideoApi videoApi, bool useHardwareDecoding, bool useTextureMips, string audioDeviceOutputName, bool useUnityAudio, bool forceResample, int channels)
		{
			this._videoApi = videoApi;
			this._useHardwareDecoding = useHardwareDecoding;
			this._useTextureMips = useTextureMips;
			this._audioDeviceOutputName = audioDeviceOutputName;
			this._useUnityAudio = useUnityAudio;
			this._forceAudioResample = forceResample;
			this._desiredAudioChannels = channels;
		}

		// Token: 0x0600020C RID: 524 RVA: 0x0000B904 File Offset: 0x00009B04
		public override string GetVersion()
		{
			return WindowsMediaPlayer._version;
		}

		// Token: 0x0600020D RID: 525 RVA: 0x0000B90C File Offset: 0x00009B0C
		public override bool OpenVideoFromFile(string path, long offset, string httpHeaderJson)
		{
			this.CloseVideo();
			int channels = WindowsMediaPlayer.CalculateClosestViableChannelNumber(this._desiredAudioChannels);
			this._instance = WindowsMediaPlayer.Native.OpenSource(this._instance, path, (int)this._videoApi, this._useHardwareDecoding, this._useTextureMips, this._audioDeviceOutputName, this._useUnityAudio, this._forceAudioResample, channels);
			if (this._instance == IntPtr.Zero)
			{
				this.DisplayLoadFailureSuggestion(path);
				return false;
			}
			WindowsMediaPlayer.Native.SetUnityAudioEnabled(this._instance, this._useUnityAudio);
			return true;
		}

		// Token: 0x0600020E RID: 526 RVA: 0x0000B994 File Offset: 0x00009B94
		public override bool OpenVideoFromBuffer(byte[] buffer)
		{
			this.CloseVideo();
			this._instance = WindowsMediaPlayer.Native.OpenSourceFromBuffer(this._instance, buffer, (ulong)((long)buffer.Length), (int)this._videoApi, this._useHardwareDecoding, this._useTextureMips, this._audioDeviceOutputName, this._useUnityAudio);
			if (this._instance == IntPtr.Zero)
			{
				return false;
			}
			WindowsMediaPlayer.Native.SetUnityAudioEnabled(this._instance, this._useUnityAudio);
			return true;
		}

		// Token: 0x0600020F RID: 527 RVA: 0x0000BA04 File Offset: 0x00009C04
		private void DisplayLoadFailureSuggestion(string path)
		{
			bool flag = this._videoApi == Windows.VideoApi.DirectShow || SystemInfo.operatingSystem.Contains("Windows 7") || SystemInfo.operatingSystem.Contains("Windows Vista") || SystemInfo.operatingSystem.Contains("Windows XP");
			if (flag && path.Contains(".mp4"))
			{
				GlobalData.Debug_LogWarning("[AVProVideo] The native Windows DirectShow H.264 decoder doesn't support videos with resolution above 1920x1080. You may need to reduce your video resolution, switch to another codec (such as DivX or Hap), or install 3rd party DirectShow codec (eg LAV Filters).  This shouldn't be a problem for Windows 8 and above as it has a native limitation of 3840x2160.");
			}
		}

		// Token: 0x06000210 RID: 528 RVA: 0x0000BA78 File Offset: 0x00009C78
		public override void CloseVideo()
		{
			this._width = 0;
			this._height = 0;
			this._frameRate = 0f;
			this._hasAudio = (this._hasVideo = false);
			this._hasMetaData = false;
			this._canPlay = false;
			this._isPaused = false;
			this._isPlaying = false;
			this._bLoop = false;
			this._audioMuted = false;
			this._volume = 1f;
			this._balance = 0f;
			this._lastFrameCount = 0;
			this._displayRate = 0f;
			this._displayRateTimer = 0f;
			this._queueSetAudioTrackIndex = -1;
			this._supportsLinearColorSpace = true;
			this._lastError = ErrorCode.None;
			this._nativeTexture = IntPtr.Zero;
			if (this._texture != null)
			{
				UnityEngine.Object.Destroy(this._texture);
				this._texture = null;
			}
			if (this._instance != IntPtr.Zero)
			{
				WindowsMediaPlayer.Native.CloseSource(this._instance);
				this._instance = IntPtr.Zero;
			}
			WindowsMediaPlayer.IssueRenderThreadEvent(WindowsMediaPlayer.Native.RenderThreadEvent.FreeTextures);
		}

		// Token: 0x06000211 RID: 529 RVA: 0x0000BB80 File Offset: 0x00009D80
		public override void SetLooping(bool looping)
		{
			this._bLoop = looping;
			WindowsMediaPlayer.Native.SetLooping(this._instance, looping);
		}

		// Token: 0x06000212 RID: 530 RVA: 0x0000BB98 File Offset: 0x00009D98
		public override bool IsLooping()
		{
			return this._bLoop;
		}

		// Token: 0x06000213 RID: 531 RVA: 0x0000BBA0 File Offset: 0x00009DA0
		public override bool HasMetaData()
		{
			return this._hasMetaData;
		}

		// Token: 0x06000214 RID: 532 RVA: 0x0000BBA8 File Offset: 0x00009DA8
		public override bool HasAudio()
		{
			return this._hasAudio;
		}

		// Token: 0x06000215 RID: 533 RVA: 0x0000BBB0 File Offset: 0x00009DB0
		public override bool HasVideo()
		{
			return this._hasVideo;
		}

		// Token: 0x06000216 RID: 534 RVA: 0x0000BBB8 File Offset: 0x00009DB8
		public override bool CanPlay()
		{
			return this._canPlay;
		}

		// Token: 0x06000217 RID: 535 RVA: 0x0000BBC0 File Offset: 0x00009DC0
		public override void Play()
		{
			this._isPlaying = true;
			this._isPaused = false;
			WindowsMediaPlayer.Native.Play(this._instance);
		}

		// Token: 0x06000218 RID: 536 RVA: 0x0000BBDC File Offset: 0x00009DDC
		public override void Pause()
		{
			this._isPlaying = false;
			this._isPaused = true;
			WindowsMediaPlayer.Native.Pause(this._instance);
		}

		// Token: 0x06000219 RID: 537 RVA: 0x0000BBF8 File Offset: 0x00009DF8
		public override void Stop()
		{
			this._isPlaying = false;
			this._isPaused = false;
			WindowsMediaPlayer.Native.Pause(this._instance);
		}

		// Token: 0x0600021A RID: 538 RVA: 0x0000BC14 File Offset: 0x00009E14
		public override bool IsSeeking()
		{
			return WindowsMediaPlayer.Native.IsSeeking(this._instance);
		}

		// Token: 0x0600021B RID: 539 RVA: 0x0000BC24 File Offset: 0x00009E24
		public override bool IsPlaying()
		{
			return this._isPlaying;
		}

		// Token: 0x0600021C RID: 540 RVA: 0x0000BC2C File Offset: 0x00009E2C
		public override bool IsPaused()
		{
			return this._isPaused;
		}

		// Token: 0x0600021D RID: 541 RVA: 0x0000BC34 File Offset: 0x00009E34
		public override bool IsFinished()
		{
			return WindowsMediaPlayer.Native.IsFinished(this._instance);
		}

		// Token: 0x0600021E RID: 542 RVA: 0x0000BC44 File Offset: 0x00009E44
		public override bool IsBuffering()
		{
			return WindowsMediaPlayer.Native.IsBuffering(this._instance);
		}

		// Token: 0x0600021F RID: 543 RVA: 0x0000BC54 File Offset: 0x00009E54
		public override float GetDurationMs()
		{
			return WindowsMediaPlayer.Native.GetDuration(this._instance) * 1000f;
		}

		// Token: 0x06000220 RID: 544 RVA: 0x0000BC68 File Offset: 0x00009E68
		public override int GetVideoWidth()
		{
			return this._width;
		}

		// Token: 0x06000221 RID: 545 RVA: 0x0000BC70 File Offset: 0x00009E70
		public override int GetVideoHeight()
		{
			return this._height;
		}

		// Token: 0x06000222 RID: 546 RVA: 0x0000BC78 File Offset: 0x00009E78
		public override float GetVideoFrameRate()
		{
			return this._frameRate;
		}

		// Token: 0x06000223 RID: 547 RVA: 0x0000BC80 File Offset: 0x00009E80
		public override float GetVideoDisplayRate()
		{
			return this._displayRate;
		}

		// Token: 0x06000224 RID: 548 RVA: 0x0000BC88 File Offset: 0x00009E88
		public override Texture GetTexture(int index)
		{
			Texture result = null;
			if (WindowsMediaPlayer.Native.GetTextureFrameCount(this._instance) > 0)
			{
				result = this._texture;
			}
			return result;
		}

		// Token: 0x06000225 RID: 549 RVA: 0x0000BCB0 File Offset: 0x00009EB0
		public override int GetTextureFrameCount()
		{
			return WindowsMediaPlayer.Native.GetTextureFrameCount(this._instance);
		}

		// Token: 0x06000226 RID: 550 RVA: 0x0000BCC0 File Offset: 0x00009EC0
		public override long GetTextureTimeStamp()
		{
			return WindowsMediaPlayer.Native.GetTextureTimeStamp(this._instance);
		}

		// Token: 0x06000227 RID: 551 RVA: 0x0000BCD0 File Offset: 0x00009ED0
		public override bool RequiresVerticalFlip()
		{
			return this._isTextureTopDown;
		}

		// Token: 0x06000228 RID: 552 RVA: 0x0000BCD8 File Offset: 0x00009ED8
		public override void Rewind()
		{
			this.Seek(0f);
		}

		// Token: 0x06000229 RID: 553 RVA: 0x0000BCE8 File Offset: 0x00009EE8
		public override void Seek(float timeMs)
		{
			WindowsMediaPlayer.Native.SetCurrentTime(this._instance, timeMs / 1000f, false);
		}

		// Token: 0x0600022A RID: 554 RVA: 0x0000BD00 File Offset: 0x00009F00
		public override void SeekFast(float timeMs)
		{
			WindowsMediaPlayer.Native.SetCurrentTime(this._instance, timeMs / 1000f, true);
		}

		// Token: 0x0600022B RID: 555 RVA: 0x0000BD18 File Offset: 0x00009F18
		public override float GetCurrentTimeMs()
		{
			return WindowsMediaPlayer.Native.GetCurrentTime(this._instance) * 1000f;
		}

		// Token: 0x0600022C RID: 556 RVA: 0x0000BD2C File Offset: 0x00009F2C
		public override void SetPlaybackRate(float rate)
		{
			WindowsMediaPlayer.Native.SetPlaybackRate(this._instance, rate);
		}

		// Token: 0x0600022D RID: 557 RVA: 0x0000BD3C File Offset: 0x00009F3C
		public override float GetPlaybackRate()
		{
			return WindowsMediaPlayer.Native.GetPlaybackRate(this._instance);
		}

		// Token: 0x0600022E RID: 558 RVA: 0x0000BD4C File Offset: 0x00009F4C
		public override float GetBufferingProgress()
		{
			return WindowsMediaPlayer.Native.GetBufferingProgress(this._instance);
		}

		// Token: 0x0600022F RID: 559 RVA: 0x0000BD5C File Offset: 0x00009F5C
		public override int GetBufferedTimeRangeCount()
		{
			return this._bufferedTimeRangeCount;
		}

		// Token: 0x06000230 RID: 560 RVA: 0x0000BD64 File Offset: 0x00009F64
		public override bool GetBufferedTimeRange(int index, ref float startTimeMs, ref float endTimeMs)
		{
			bool result = false;
			if (index >= 0 && index < this._bufferedTimeRangeCount)
			{
				result = true;
				startTimeMs = 1000f * this._bufferedTimeRanges[index * 2];
				endTimeMs = 1000f * this._bufferedTimeRanges[index * 2 + 1];
			}
			return result;
		}

		// Token: 0x06000231 RID: 561 RVA: 0x0000BDB0 File Offset: 0x00009FB0
		public override void MuteAudio(bool bMuted)
		{
			this._audioMuted = bMuted;
			WindowsMediaPlayer.Native.SetMuted(this._instance, this._audioMuted);
		}

		// Token: 0x06000232 RID: 562 RVA: 0x0000BDCC File Offset: 0x00009FCC
		public override bool IsMuted()
		{
			return this._audioMuted;
		}

		// Token: 0x06000233 RID: 563 RVA: 0x0000BDD4 File Offset: 0x00009FD4
		public override void SetVolume(float volume)
		{
			this._volume = volume;
			WindowsMediaPlayer.Native.SetVolume(this._instance, volume);
		}

		// Token: 0x06000234 RID: 564 RVA: 0x0000BDEC File Offset: 0x00009FEC
		public override float GetVolume()
		{
			return this._volume;
		}

		// Token: 0x06000235 RID: 565 RVA: 0x0000BDF4 File Offset: 0x00009FF4
		public override void SetBalance(float balance)
		{
			this._balance = balance;
			WindowsMediaPlayer.Native.SetBalance(this._instance, balance);
		}

		// Token: 0x06000236 RID: 566 RVA: 0x0000BE0C File Offset: 0x0000A00C
		public override float GetBalance()
		{
			return this._balance;
		}

		// Token: 0x06000237 RID: 567 RVA: 0x0000BE14 File Offset: 0x0000A014
		public override int GetAudioTrackCount()
		{
			return WindowsMediaPlayer.Native.GetAudioTrackCount(this._instance);
		}

		// Token: 0x06000238 RID: 568 RVA: 0x0000BE24 File Offset: 0x0000A024
		public override int GetCurrentAudioTrack()
		{
			return WindowsMediaPlayer.Native.GetAudioTrack(this._instance);
		}

		// Token: 0x06000239 RID: 569 RVA: 0x0000BE34 File Offset: 0x0000A034
		public override void SetAudioTrack(int index)
		{
			this._queueSetAudioTrackIndex = index;
		}

		// Token: 0x0600023A RID: 570 RVA: 0x0000BE40 File Offset: 0x0000A040
		public override int GetVideoTrackCount()
		{
			int result = 0;
			if (this.HasVideo())
			{
				result = 1;
			}
			return result;
		}

		// Token: 0x0600023B RID: 571 RVA: 0x0000BE60 File Offset: 0x0000A060
		public override bool IsPlaybackStalled()
		{
			return WindowsMediaPlayer.Native.IsPlaybackStalled(this._instance);
		}

		// Token: 0x0600023C RID: 572 RVA: 0x0000BE70 File Offset: 0x0000A070
		public override string GetCurrentAudioTrackId()
		{
			return string.Empty;
		}

		// Token: 0x0600023D RID: 573 RVA: 0x0000BE78 File Offset: 0x0000A078
		public override int GetCurrentAudioTrackBitrate()
		{
			return 0;
		}

		// Token: 0x0600023E RID: 574 RVA: 0x0000BE7C File Offset: 0x0000A07C
		public override int GetCurrentVideoTrack()
		{
			return 0;
		}

		// Token: 0x0600023F RID: 575 RVA: 0x0000BE80 File Offset: 0x0000A080
		public override void SetVideoTrack(int index)
		{
		}

		// Token: 0x06000240 RID: 576 RVA: 0x0000BE84 File Offset: 0x0000A084
		public override string GetCurrentVideoTrackId()
		{
			return string.Empty;
		}

		// Token: 0x06000241 RID: 577 RVA: 0x0000BE8C File Offset: 0x0000A08C
		public override int GetCurrentVideoTrackBitrate()
		{
			return 0;
		}

		// Token: 0x06000242 RID: 578 RVA: 0x0000BE90 File Offset: 0x0000A090
		public override void Update()
		{
			WindowsMediaPlayer.Native.Update(this._instance);
			this._lastError = (ErrorCode)WindowsMediaPlayer.Native.GetLastErrorCode(this._instance);
			if (this._queueSetAudioTrackIndex >= 0 && this._hasAudio)
			{
				WindowsMediaPlayer.Native.SetAudioTrack(this._instance, this._queueSetAudioTrackIndex);
				this._queueSetAudioTrackIndex = -1;
			}
			this._bufferedTimeRangeCount = WindowsMediaPlayer.Native.GetBufferedRanges(this._instance, this._bufferedTimeRanges, this._bufferedTimeRanges.Length / 2);
			if (this._bufferedTimeRangeCount > this._bufferedTimeRanges.Length / 2)
			{
				this._bufferedTimeRanges = new float[this._bufferedTimeRangeCount * 2];
				this._bufferedTimeRangeCount = WindowsMediaPlayer.Native.GetBufferedRanges(this._instance, this._bufferedTimeRanges, this._bufferedTimeRanges.Length / 2);
			}
			this.UpdateSubtitles();
			if (!this._canPlay)
			{
				if (!this._hasMetaData && WindowsMediaPlayer.Native.HasMetaData(this._instance))
				{
					if (WindowsMediaPlayer.Native.HasVideo(this._instance))
					{
						this._width = WindowsMediaPlayer.Native.GetWidth(this._instance);
						this._height = WindowsMediaPlayer.Native.GetHeight(this._instance);
						this._frameRate = WindowsMediaPlayer.Native.GetFrameRate(this._instance);
						if (this._width > 0 && this._height > 0)
						{
							this._hasVideo = true;
							if (Mathf.Max(this._width, this._height) > SystemInfo.maxTextureSize)
							{
								GlobalData.Debug_LogError(string.Format("[AVProVideo] Video dimensions ({0}x{1}) larger than maxTextureSize ({2} for current build target)", this._width, this._height, SystemInfo.maxTextureSize));
								this._width = (this._height = 0);
								this._hasVideo = false;
							}
						}
						if (this._hasVideo && WindowsMediaPlayer.Native.HasAudio(this._instance))
						{
							this._hasAudio = true;
						}
					}
					else if (WindowsMediaPlayer.Native.HasAudio(this._instance))
					{
						this._hasAudio = true;
					}
					if (this._hasVideo || this._hasAudio)
					{
						this._hasMetaData = true;
					}
					this._playerDescription = Marshal.PtrToStringAnsi(WindowsMediaPlayer.Native.GetPlayerDescription(this._instance));
					this._supportsLinearColorSpace = !this._playerDescription.Contains("MF-MediaEngine-Hardware");
					Helper.LogInfo(string.Concat(new object[]
					{
						"Using playback path: ",
						this._playerDescription,
						" (",
						this._width,
						"x",
						this._height,
						"@",
						this.GetVideoFrameRate().ToString("F2"),
						")"
					}), null);
					if (this._hasVideo)
					{
						this.OnTextureSizeChanged();
					}
				}
				if (this._hasMetaData)
				{
					this._canPlay = WindowsMediaPlayer.Native.CanPlay(this._instance);
				}
			}
			if (this._hasVideo)
			{
				IntPtr texturePointer = WindowsMediaPlayer.Native.GetTexturePointer(this._instance);
				if (this._texture != null && this._nativeTexture != IntPtr.Zero && this._nativeTexture != texturePointer)
				{
					this._width = WindowsMediaPlayer.Native.GetWidth(this._instance);
					this._height = WindowsMediaPlayer.Native.GetHeight(this._instance);
					if (texturePointer == IntPtr.Zero || this._width != this._texture.width || this._height != this._texture.height)
					{
						if (this._width != this._texture.width || this._height != this._texture.height)
						{
							Helper.LogInfo(string.Concat(new object[]
							{
								"Texture size changed: ",
								this._width,
								" X ",
								this._height
							}), null);
							this.OnTextureSizeChanged();
						}
						this._nativeTexture = IntPtr.Zero;
						UnityEngine.Object.Destroy(this._texture);
						this._texture = null;
					}
					else if (this._nativeTexture != texturePointer)
					{
						this._texture.UpdateExternalTexture(texturePointer);
						this._nativeTexture = texturePointer;
					}
				}
				if (this._textureQuality != QualitySettings.masterTextureLimit)
				{
					if (this._texture != null && this._nativeTexture != IntPtr.Zero && this._texture.GetNativeTexturePtr() == IntPtr.Zero)
					{
						this._texture.UpdateExternalTexture(this._nativeTexture);
					}
					this._textureQuality = QualitySettings.masterTextureLimit;
				}
				if (this._texture == null && this._width > 0 && this._height > 0 && texturePointer != IntPtr.Zero)
				{
					this._isTextureTopDown = WindowsMediaPlayer.Native.IsTextureTopDown(this._instance);
					this._texture = Texture2D.CreateExternalTexture(this._width, this._height, TextureFormat.RGBA32, this._useTextureMips, false, texturePointer);
					if (this._texture != null)
					{
						this._nativeTexture = texturePointer;
						this.ApplyTextureProperties(this._texture);
					}
					else
					{
						GlobalData.Debug_LogError("[AVProVideo] Failed to create texture");
					}
				}
			}
		}

		// Token: 0x06000243 RID: 579 RVA: 0x0000C3D8 File Offset: 0x0000A5D8
		private void OnTextureSizeChanged()
		{
			if ((this._width == 720 || this._height == 480) && this._playerDescription.Contains("DirectShow"))
			{
				GlobalData.Debug_LogWarning("[AVProVideo] If video fails to play then it may be due to the resolution being higher than 1920x1080 which is the limitation of the Microsoft DirectShow H.264 decoder.\nTo resolve this you can either use Windows 8 or above (and disable 'Force DirectShow' option), resize your video, use a different codec (such as Hap or DivX), or install a 3rd party H.264 decoder such as LAV Filters.");
			}
			else if ((this._width <= 1920 && this._height <= 1080) || this._playerDescription.Contains("MF-MediaEngine-Software"))
			{
			}
		}

		// Token: 0x06000244 RID: 580 RVA: 0x0000C460 File Offset: 0x0000A660
		private void UpdateDisplayFrameRate()
		{
			this._displayRateTimer += Time.deltaTime;
			if (this._displayRateTimer >= 0.5f)
			{
				int textureFrameCount = WindowsMediaPlayer.Native.GetTextureFrameCount(this._instance);
				this._displayRate = (float)(textureFrameCount - this._lastFrameCount) / this._displayRateTimer;
				this._displayRateTimer -= 0.5f;
				if (this._displayRateTimer >= 0.5f)
				{
					this._displayRateTimer = 0f;
				}
				this._lastFrameCount = textureFrameCount;
			}
		}

		// Token: 0x06000245 RID: 581 RVA: 0x0000C4E8 File Offset: 0x0000A6E8
		public override void Render()
		{
			this.UpdateDisplayFrameRate();
			WindowsMediaPlayer.IssueRenderThreadEvent(WindowsMediaPlayer.Native.RenderThreadEvent.UpdateAllTextures);
		}

		// Token: 0x06000246 RID: 582 RVA: 0x0000C4F8 File Offset: 0x0000A6F8
		public override void Dispose()
		{
			this.CloseVideo();
		}

		// Token: 0x06000247 RID: 583 RVA: 0x0000C500 File Offset: 0x0000A700
		public override void GrabAudio(float[] buffer, int floatCount, int channelCount)
		{
			WindowsMediaPlayer.Native.GrabAudio(this._instance, buffer, floatCount, channelCount);
		}

		// Token: 0x06000248 RID: 584 RVA: 0x0000C510 File Offset: 0x0000A710
		public override bool PlayerSupportsLinearColorSpace()
		{
			return this._supportsLinearColorSpace;
		}

		// Token: 0x06000249 RID: 585 RVA: 0x0000C518 File Offset: 0x0000A718
		private static void IssueRenderThreadEvent(WindowsMediaPlayer.Native.RenderThreadEvent renderEvent)
		{
			if (renderEvent == WindowsMediaPlayer.Native.RenderThreadEvent.UpdateAllTextures)
			{
				GL.IssuePluginEvent(WindowsMediaPlayer._nativeFunction_UpdateAllTextures, 0);
			}
			else if (renderEvent == WindowsMediaPlayer.Native.RenderThreadEvent.FreeTextures)
			{
				GL.IssuePluginEvent(WindowsMediaPlayer._nativeFunction_FreeTextures, 0);
			}
		}

		// Token: 0x0600024A RID: 586 RVA: 0x0000C544 File Offset: 0x0000A744
		private static string GetPluginVersion()
		{
			return Marshal.PtrToStringAnsi(WindowsMediaPlayer.Native.GetPluginVersion());
		}

		// Token: 0x0600024B RID: 587 RVA: 0x0000C550 File Offset: 0x0000A750
		public override void OnEnable()
		{
			base.OnEnable();
			if (this._texture != null && this._nativeTexture != IntPtr.Zero && this._texture.GetNativeTexturePtr() == IntPtr.Zero)
			{
				this._texture.UpdateExternalTexture(this._nativeTexture);
			}
			this._textureQuality = QualitySettings.masterTextureLimit;
		}

		// Token: 0x04000189 RID: 393
		private bool _forceAudioResample = true;

		// Token: 0x0400018A RID: 394
		private int _desiredAudioChannels = 2;

		// Token: 0x0400018B RID: 395
		private bool _useUnityAudio;

		// Token: 0x0400018C RID: 396
		private string _audioDeviceOutputName = string.Empty;

		// Token: 0x0400018D RID: 397
		private bool _isPlaying;

		// Token: 0x0400018E RID: 398
		private bool _isPaused;

		// Token: 0x0400018F RID: 399
		private bool _audioMuted;

		// Token: 0x04000190 RID: 400
		private float _volume = 1f;

		// Token: 0x04000191 RID: 401
		private float _balance;

		// Token: 0x04000192 RID: 402
		private bool _bLoop;

		// Token: 0x04000193 RID: 403
		private bool _canPlay;

		// Token: 0x04000194 RID: 404
		private bool _hasMetaData;

		// Token: 0x04000195 RID: 405
		private int _width;

		// Token: 0x04000196 RID: 406
		private int _height;

		// Token: 0x04000197 RID: 407
		private float _frameRate;

		// Token: 0x04000198 RID: 408
		private bool _hasAudio;

		// Token: 0x04000199 RID: 409
		private bool _hasVideo;

		// Token: 0x0400019A RID: 410
		private bool _isTextureTopDown = true;

		// Token: 0x0400019B RID: 411
		private IntPtr _nativeTexture = IntPtr.Zero;

		// Token: 0x0400019C RID: 412
		private Texture2D _texture;

		// Token: 0x0400019D RID: 413
		private IntPtr _instance = IntPtr.Zero;

		// Token: 0x0400019E RID: 414
		private float _displayRateTimer;

		// Token: 0x0400019F RID: 415
		private int _lastFrameCount;

		// Token: 0x040001A0 RID: 416
		private float _displayRate = 1f;

		// Token: 0x040001A1 RID: 417
		private Windows.VideoApi _videoApi;

		// Token: 0x040001A2 RID: 418
		private bool _useHardwareDecoding = true;

		// Token: 0x040001A3 RID: 419
		private bool _useTextureMips;

		// Token: 0x040001A4 RID: 420
		private int _queueSetAudioTrackIndex = -1;

		// Token: 0x040001A5 RID: 421
		private bool _supportsLinearColorSpace = true;

		// Token: 0x040001A6 RID: 422
		private int _bufferedTimeRangeCount;

		// Token: 0x040001A7 RID: 423
		private float[] _bufferedTimeRanges = new float[0];

		// Token: 0x040001A8 RID: 424
		private static bool _isInitialised;

		// Token: 0x040001A9 RID: 425
		private static string _version = "Plug-in not yet initialised";

		// Token: 0x040001AA RID: 426
		private static IntPtr _nativeFunction_UpdateAllTextures;

		// Token: 0x040001AB RID: 427
		private static IntPtr _nativeFunction_FreeTextures;

		// Token: 0x040001AC RID: 428
		private int _textureQuality = QualitySettings.masterTextureLimit;

		// Token: 0x02000044 RID: 68
		private struct Native
		{
			// Token: 0x0600024D RID: 589
			[DllImport("AVProVideo")]
			public static extern bool Init(bool linearColorSpace, bool isD3D11NoSingleThreaded);

			// Token: 0x0600024E RID: 590
			[DllImport("AVProVideo")]
			public static extern void Deinit();

			// Token: 0x0600024F RID: 591
			[DllImport("AVProVideo")]
			public static extern IntPtr GetPluginVersion();

			// Token: 0x06000250 RID: 592
			[DllImport("AVProVideo")]
			public static extern bool IsTrialVersion();

			// Token: 0x06000251 RID: 593
			[DllImport("AVProVideo")]
			public static extern IntPtr OpenSource(IntPtr instance, [MarshalAs(UnmanagedType.LPWStr)] string path, int videoApiIndex, bool useHardwareDecoding, bool generateTextureMips, [MarshalAs(UnmanagedType.LPWStr)] string forceAudioOutputDeviceName, bool useUnityAudio, bool forceResample, int channels);

			// Token: 0x06000252 RID: 594
			[DllImport("AVProVideo")]
			public static extern IntPtr OpenSourceFromBuffer(IntPtr instance, byte[] buffer, ulong bufferLength, int videoApiIndex, bool useHardwareDecoding, bool generateTextureMips, [MarshalAs(UnmanagedType.LPWStr)] string forceAudioOutputDeviceName, bool useUnityAudio);

			// Token: 0x06000253 RID: 595
			[DllImport("AVProVideo")]
			public static extern void CloseSource(IntPtr instance);

			// Token: 0x06000254 RID: 596
			[DllImport("AVProVideo")]
			public static extern IntPtr GetPlayerDescription(IntPtr instance);

			// Token: 0x06000255 RID: 597
			[DllImport("AVProVideo")]
			public static extern int GetLastErrorCode(IntPtr instance);

			// Token: 0x06000256 RID: 598
			[DllImport("AVProVideo")]
			public static extern void Play(IntPtr instance);

			// Token: 0x06000257 RID: 599
			[DllImport("AVProVideo")]
			public static extern void Pause(IntPtr instance);

			// Token: 0x06000258 RID: 600
			[DllImport("AVProVideo")]
			public static extern void SetMuted(IntPtr instance, bool muted);

			// Token: 0x06000259 RID: 601
			[DllImport("AVProVideo")]
			public static extern void SetVolume(IntPtr instance, float volume);

			// Token: 0x0600025A RID: 602
			[DllImport("AVProVideo")]
			public static extern void SetBalance(IntPtr instance, float volume);

			// Token: 0x0600025B RID: 603
			[DllImport("AVProVideo")]
			public static extern void SetLooping(IntPtr instance, bool looping);

			// Token: 0x0600025C RID: 604
			[DllImport("AVProVideo")]
			public static extern bool HasVideo(IntPtr instance);

			// Token: 0x0600025D RID: 605
			[DllImport("AVProVideo")]
			public static extern bool HasAudio(IntPtr instance);

			// Token: 0x0600025E RID: 606
			[DllImport("AVProVideo")]
			public static extern int GetWidth(IntPtr instance);

			// Token: 0x0600025F RID: 607
			[DllImport("AVProVideo")]
			public static extern int GetHeight(IntPtr instance);

			// Token: 0x06000260 RID: 608
			[DllImport("AVProVideo")]
			public static extern float GetFrameRate(IntPtr instance);

			// Token: 0x06000261 RID: 609
			[DllImport("AVProVideo")]
			public static extern float GetDuration(IntPtr instance);

			// Token: 0x06000262 RID: 610
			[DllImport("AVProVideo")]
			public static extern int GetAudioTrackCount(IntPtr instance);

			// Token: 0x06000263 RID: 611
			[DllImport("AVProVideo")]
			public static extern bool IsPlaybackStalled(IntPtr instance);

			// Token: 0x06000264 RID: 612
			[DllImport("AVProVideo")]
			public static extern bool HasMetaData(IntPtr instance);

			// Token: 0x06000265 RID: 613
			[DllImport("AVProVideo")]
			public static extern bool CanPlay(IntPtr instance);

			// Token: 0x06000266 RID: 614
			[DllImport("AVProVideo")]
			public static extern bool IsSeeking(IntPtr instance);

			// Token: 0x06000267 RID: 615
			[DllImport("AVProVideo")]
			public static extern bool IsFinished(IntPtr instance);

			// Token: 0x06000268 RID: 616
			[DllImport("AVProVideo")]
			public static extern bool IsBuffering(IntPtr instance);

			// Token: 0x06000269 RID: 617
			[DllImport("AVProVideo")]
			public static extern float GetCurrentTime(IntPtr instance);

			// Token: 0x0600026A RID: 618
			[DllImport("AVProVideo")]
			public static extern void SetCurrentTime(IntPtr instance, float time, bool fast);

			// Token: 0x0600026B RID: 619
			[DllImport("AVProVideo")]
			public static extern float GetPlaybackRate(IntPtr instance);

			// Token: 0x0600026C RID: 620
			[DllImport("AVProVideo")]
			public static extern void SetPlaybackRate(IntPtr instance, float rate);

			// Token: 0x0600026D RID: 621
			[DllImport("AVProVideo")]
			public static extern int GetAudioTrack(IntPtr instance);

			// Token: 0x0600026E RID: 622
			[DllImport("AVProVideo")]
			public static extern void SetAudioTrack(IntPtr instance, int index);

			// Token: 0x0600026F RID: 623
			[DllImport("AVProVideo")]
			public static extern float GetBufferingProgress(IntPtr instance);

			// Token: 0x06000270 RID: 624
			[DllImport("AVProVideo")]
			public static extern int GetBufferedRanges(IntPtr instance, float[] timeArray, int arrayCount);

			// Token: 0x06000271 RID: 625
			[DllImport("AVProVideo")]
			public static extern void Update(IntPtr instance);

			// Token: 0x06000272 RID: 626
			[DllImport("AVProVideo")]
			public static extern IntPtr GetTexturePointer(IntPtr instance);

			// Token: 0x06000273 RID: 627
			[DllImport("AVProVideo")]
			public static extern bool IsTextureTopDown(IntPtr instance);

			// Token: 0x06000274 RID: 628
			[DllImport("AVProVideo")]
			public static extern int GetTextureFrameCount(IntPtr instance);

			// Token: 0x06000275 RID: 629
			[DllImport("AVProVideo")]
			public static extern long GetTextureTimeStamp(IntPtr instance);

			// Token: 0x06000276 RID: 630
			[DllImport("AVProVideo")]
			public static extern IntPtr GetRenderEventFunc_UpdateAllTextures();

			// Token: 0x06000277 RID: 631
			[DllImport("AVProVideo")]
			public static extern IntPtr GetRenderEventFunc_FreeTextures();

			// Token: 0x06000278 RID: 632
			[DllImport("AVProVideo")]
			public static extern void SetUnityAudioEnabled(IntPtr instance, bool enabled);

			// Token: 0x06000279 RID: 633
			[DllImport("AVProVideo")]
			public static extern void GrabAudio(IntPtr instance, float[] buffer, int floatCount, int channelCount);

			// Token: 0x0600027A RID: 634
			[DllImport("AVProVideo")]
			public static extern int GetAudioChannelCount(IntPtr instance);

			// Token: 0x040001AD RID: 429
			public const int PluginID = 262537216;

			// Token: 0x02000045 RID: 69
			public enum RenderThreadEvent
			{
				// Token: 0x040001AF RID: 431
				UpdateAllTextures,
				// Token: 0x040001B0 RID: 432
				FreeTextures
			}
		}
	}
}
